package com.gaussian.property.app.controller;

import com.gaussian.property.app.service.MessageService;
import com.gaussian.property.app.vo.message.ProjectMessageVo;
import com.gaussian.property.app.vo.message.ReplyForm;
import com.gaussian.property.module.biz.entity.AppUser;
import com.songqi.common.core.domain.R;
import com.songqi.common.web.request.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @description:
 * @author: songqi(13776346982)
 * @date: 2024/4/19 14:32
 */
@Api(tags = "项目留言操作相关")
@RestController
@Validated
@RequestMapping("message/")
public class MessageController extends BaseController {


    @Resource
    private MessageService messageService;


    @ApiOperation("查询项目留言")
    @GetMapping("queryMessages")
    public R<List<ProjectMessageVo>> queryMessages(@Valid @NotBlank(message = "month参数不能为空") @ApiParam("年月。格式yyyyMM") String month,
                                                    @NotBlank(message = "项目未配置稽核表，联系管理员") @ApiParam("项目id") String projectId) {
        AppUser appUser = (AppUser)getTokenUser();
        return R.success(messageService.queryMessage(month, projectId, appUser.getAppUserId()));
    }

    @ApiOperation("回复项目留言")
    @PostMapping("reply")
    public R<Void> reply(@Validated @RequestBody ReplyForm replyForm){
        messageService.reply(replyForm);
        return success();
    }
}
